﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Kevin.Framework.Validation
{
    internal class DoubleRangeValidator:Validator
    {
         private Double lowerBound;
         private Double upperBound;

         public DoubleRangeValidator(Double lowerBound, Double upperBound)
            : base(string.Empty, string.Empty)
        {
            this.lowerBound = lowerBound;
            this.upperBound = upperBound;
        }

         public DoubleRangeValidator(Double lowerBound, Double upperBound, string messageTemplate, string tag)
            : base(messageTemplate, tag)
        {
            this.lowerBound = lowerBound;
            this.upperBound = upperBound;
        }

        protected internal override void DoValidate(object objectToValidate,
            object currentTarget,
            string key,
            ValidationResults validationResults)
        {
            bool isValid = false;

            if (objectToValidate != null)
            {
                RangeChecker<Double> checker = new RangeChecker<Double>(this.lowerBound, this.upperBound);
                isValid = checker.IsInRange((Double)objectToValidate);
            }

            if (isValid == false)
                RecordValidationResult(validationResults, this.MessageTemplate, currentTarget, key);
        }
    }
}
